function revertKgroup(list, n) {
    let res = [];
    while (list.length) {
        let temp = list.splice(0, n);
        console.log(temp);
        res.push(temp);
    }
    console.log(res);
}


revertKgroup([1, 2, 3, 4], 4)